<template>
	<view>
		<!-- <text>商品列表页面</text> -->
		<view class="goods-list">
			<view v-for="(goods,index) in goodsList" :key='index' @click='goGoodsDetail(goods)'>
				<goods-item :goods='goods' @click='handlerLele'></goods-item>
			</view>
			
		</view>
	</view>
</template>

<script>
	import {goodsListData} from '@/api/goods-list-request.js';
	export default {
		data() {
			return {
				queryObj:{
					query:'',
					cid:'',
					pagenum:1,
					pagesize:10
				},
				goodsList:[],
				total:0,
				isLoading:false
			};
		},
		onLoad(options){
			console.log(options);
			this.queryObj.query = options.query || '';
			this.queryObj.cid = options.cid || '';
			
			this.getGoodsList();
		},
		methods:{
			handlerLele(){
				console.log('lele');
			},
			async getGoodsList(callback){
				this.isLoading = true;
				callback && callback();
				const {data:res} = await goodsListData(this.queryObj);
				this.isLoading = false;
				console.log(res);
				if(res.meta.status !== 200){
					return uni.showToast({
						title:'数据请求失败，请稍后',
						icon:'none'
					})
				};
				// if(res.meta,status !== 200) return uni.$showMsg();
				this.goodsList = [...this.goodsList,...res.message.goods];
				this.total = res.message.total;
				
			},
			goGoodsDetail(goods){
				console.log('测试能不能去详情页面');
				uni.navigateTo({
					url:'/subpkg/goods-detail/goods-detail?goods_id=' + goods.goods_id
				})
				
			}
		},
		onReachBottom() {
			console.log('测试下拉会不会触发');
			if(this.queryObj.pagenum * this.queryObj.pagesize >=this.total) return uni.$showMsg('数据加载完成');
			if(this.isLoading) true;
			this.queryObj.pagenum += 1;
			this.getGoodsList();
		},
		onPullDownRefresh() {
			console.log('测试会不会刷新');
			this.queryObj.pagenum = 1;
			this.isLoading = false;
			this.goodsList = [];
			this.getGoodsList( ()=>uni.stopPullDownRefresh());
		}
	}
</script>

<style lang="scss">

</style>
